QuickTime 2.5 included new functions to support packetizing compressed data streams, primarily for video conferencing applications. These functions are discussed in Chapter 3, "Image Compression Manager," and other chapters of this book. In addition, a new field ( preferredPacketSizeInBytes ) has been added to the compression parameters structure. Codec developers need only use this field.
Packet information is appended, word-aligned, to the end of video data. It is a variable-length array of 4-byte integers, each representing the offset in bits of the end of a packet, followed by another integer containing the number of packet hints, and finally a four-byte identifier indicating the type of appended data:
[boundary #1][boundary #2]...[boundary #N][N]['pkts']
Packets are given in bits, because some types of compressed image data (such as H.261) are cut up on bit-boundaries rather than byte-boundaries.
// given: image data, length, and a packet number
// returns: a pointer to the start of the packet and a packet size, plus
// information about leading and trailing bits
char* GetNextPacket(char* data, int len, int packet, long* packet_size,
char* leading_bits, char* trailing_bits)
{
long *lp, packets;
lp = (long*) data; // 'data' must be word-aligned
lp += len/4 - 1;
if (*lp != 'pkts')
return nil;
packets = *lp[-1]; // negative indexing is good for you
if (packet >= packets)
return nil; // out of bounds
lp -= packets; // now 0-indexing into the packet array will work
if (packet == 0)
{
*packet_size = (lp[0] + 7)/8; // count the bits
*leading_bits = 0;
*trailing_bits = lp[0] % 8;
return data; // in case of 0-length packet
}
else
{
*packet_size = ( lp[pktnum] - lp[pktnum-1] + 7) / 8;
*leading_bits = lp[packet-1] % 8 ? 8 - lp[packet-1] % 8 : 0;
*trailing_bits = lp[packet] % 8;
return data + lp[packet-1] / 8;
}
}
Note that this technique can be used for further extensions by the addition of further appended formats. The last two words are always the number of words and an extension identifier.
| Previous | Chapter Contents | Chapter Top | Next |